<?php
namespace Common\Model;

use Common\Model\BaseModel;

class RoomModel extends BaseModel
{
    protected $tableName = 'room';

    public function addRoom($post)
    {

        $ret = array('status' => '', 'info' => '');
        $data = $this->returnData($post);
        if ($this->create($data)) {
            $res = null !== $data['id'] ? $this->save($data) : $this->add($data);
            if (false !== $res) {
                $ret['status'] = true;
                $ret['info'] = "Success";
            } else {
                $ret['status'] = false;
                $ret['info'] = $this->getDbError();
            }
        } else {
            $ret['status'] = false;
            $ret['info'] = $this->getError();
        }

        return $ret;
    }

    public function returnData($post)
    {
        $return['id'] = !empty($post['id']) ? intval($post['id']) : null;
        $return['room_id'] = !empty($post['room_id']) ? intval($post['room_id']) : $this->createTabCarid();
        $return['room_name'] = !empty($post['room_name']) ? addslashes($post['room_name']) : '';
        $return['staff_id'] = !empty($post['staff_id']) ? intval($post['staff_id']) : 0;
        $return['powder_amount'] = !empty($post['powder_amount']) ? intval($post['powder_amount']) : 0;
        $return['carbon_amount'] = !empty($post['carbon_amount']) ? intval($post['carbon_amount']) : 0;
        $return['blanket_amount'] = !empty($post['blanket_amount']) ? intval($post['blanket_amount']) : 0;
        $return['extinguisher_amount'] = !empty($post['extinguisher_amount']) ? intval($post['extinguisher_amount']) : 0;
        $return['building_id'] = !empty($post['building_id']) ? intval($post['building_id']) : 1 ;
        return $return;
    }

    public function getRoom($field = "*")
    {
        $res = $this->field($field)->select();
        return $res;
    }

    public function createTabCarid()   //创造机动车证申请表编号
    {
        $tab_car_id = date('YmdHis', time());
        return 'room_'.$tab_car_id;
    }

}